<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>mas</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <link href="./mas/css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
        .bd {
            background-color: pink;
            color: #000000;
        }

        body > div.bs-example {
            margin: 30px auto 10px auto;
            width: 600px;
            height: 400px;

        }

        body > div > form > div.col-md-12 > textarea.qq {
            width: 100%;
            margin-top: 20px;
        }

        body > div > form > div.col-md-12.qq1 {
            padding-left: 0px;
        }
        .de{
            display: inline-block;
            margin-left: 5px;
            cursor: pointer;
            text-decoration: none;
        }
        .de:hover{
            text-decoration: none;
            color: #0f0f0f;
        }
        a{
            text-decoration: none;
        }
        a:hover{
            text-decoration: none;
        }
        .cc{
            margin-right: 20px;
        }
        body > div.fy{
            width: 600px;
            height:60px;
            margin: 0 auto;
        }
        #bs-example-navbar-collapse-6 > form{
            width: 580px;
            float: right;
            margin-top: 10px;
        }
        #bs-example-navbar-collapse-6 > form > button.btn.btn-default.zc{
            background-color: deeppink;
            color: #f1f1f1;
        }
        #bs-example-navbar-collapse-6 > form > div.form-group{
            position: relative;
        }
        #bs-example-navbar-collapse-6 > form > div.form-group > span{
            display: none;
        }
        #bs-example-navbar-collapse-6 > form > div.form-group > p.ts{

            position: absolute;
            top: 42px;
            width: 150px;
            overflow: hidden;
            height: 25px;
            background-color: #FCF8E3;
            border: 1px solid #FAEBCC;
            color: #8A6D3B;
            padding-left: 5px;
            display: none;
        }
    </style>
    <script type="text/javascript" src="mas/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">
        /**
         * 注册
         */
        function regist() {

            window.location.href = 'index.php?reg=1';
        }
        function delv(){
            window.location.href = 'index.php';
        }
        function gr(){
            window.location.href ='gr.php';
        }
        function dj(){
            alert("请登录后留言，谢谢！");
        }
        function tc(){
            window.location.href='logout.php';
        }
    $(function(){
        dy=0;
     $("input[id='z']").focus(function(){
         username = $("input[id='x']").val();
         dui=$("#dui");
         ts1=$(".ts:eq(0)");

         $.ajax({
             url:'regajax.php',
             type:"post",
             dataType:"json",
             data:{username:username},
             success:function(data,succ,hr){
               if(data.error==0){
                   $("#dui").css('display','block').attr("class","glyphicon glyphicon-remove form-control-feedback");
                    ts1.css('display','block').text(data.info);
               }
                 if(data.error==1){
                     $("#dui").css('display','block').attr("class","glyphicon glyphicon-remove form-control-feedback");
                     ts1.css('display','block').text(data.info);
                 }
                 if(data.error==2){
                     $("#dui").css('display','block').attr("class","glyphicon glyphicon-remove form-control-feedback");
                     ts1.css('display','block').text(data.info);
                 }
                 if(data.error==4){
                     $("#dui").css('display','block').attr("class","glyphicon glyphicon-ok form-control-feedback");

                  $("#zcb").attr("type","submit");
                 }
             },
             error:function(aa,bb,cc){

//
             },context:$("input[id='x']")

         })
        })
        $("#zcb").click(function(){
            ts1=$(".ts:eq(1)");
            if($(this).val()==""){
                ts1.css('display','block').text("密码不能为空");
                $("#cui").css('display','block').attr("class","glyphicon glyphicon-remove form-control-feedback");


            }
        })
        $("input[id='x']").focus(function(){
            dui=$("#dui").css('display','none');
            ts1.css('display','none');
        })

        })
    </script>
</head>
<body>
<div class="container-fluid bd">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                data-target="#bs-example-navbar-collapse-6" aria-expanded="false">
            <span class="sr-only">看</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">小桥流水论坛</a>
    </div>

    <div class="collapse navbar-collapse " id="bs-example-navbar-collapse-6">
        <ul class="nav navbar-nav">
            <li class="active"><a href="./index.php">首页</a></li>
            <li><a href="#">论坛</a></li>
            <li><a href="#">联系方式</a></li>
        </ul>
        <?php if(isset($_GET['reg'])) { ?>
        <form class="form-inline" action="./reg.php" method="post">
            <div class="form-group">
                <label class="sr-only" for="exampleInputEmail3">姓名</label>
                <input type="text" class="form-control" id="x" placeholder="姓名" name="usename" >
                <span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" id="dui"></span>
                <p class="ts"></p>
            </div>
            <div class="form-group">
                <label class="sr-only" for="exampleInputPassword3">密码</label>
                <input type="password" class="form-control" id="z" placeholder="密码" name="password">
                <span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" id="cui" ></span>
                <p class="ts"></p>
            </div>


            <button type="button" class="btn btn-default zc" id="zcb">注册</button>
            <button type="button" class="btn btn-default zc" onclick="delv()">已有帐号</button>

        </form>
        <?php }else {?>
        <?php if(isset($_SESSION['usename'])) { ?>
        <form class="form-inline" action="" method="get">
        <button type="button" class="btn btn-default" onclick="gr()"><?php echo $_SESSION['usename']."!你好";?></button>
        <button type="button" class="btn btn-default zc" onclick="tc()" > 退出</button>
        </form>


        <?php } else{ ?>
        <form class="form-inline" action="./login.php" method="post">
            <div class="form-group">
                <label class="sr-only" for="exampleInputEmail3">姓名</label>
                <input type="text" class="form-control" id="exampleInputEmail3" placeholder="姓名" name="usename">
            </div>
            <div class="form-group">
                <label class="sr-only" for="exampleInputPassword3">密码</label>
                <input type="password" class="form-control" id="exampleInputPassword3" placeholder="密码" name="password">
            </div>

            <button type="submit" class="btn btn-default">登录</button>
            <button type="button" class="btn btn-default zc" onclick="regist()">注册</button>
        </form>
        <?php } ?>
        <?php  } ?>
    </div><!-- /.navbar-collapse -->

</div>

<div class="bs-example" data-example-id="alerts-with-links">
    <?php
    foreach ($arr as $key => $value){ ?>

    <div class="<?php echo $colora[array_rand($colora)]; ?>" role="alert">
        <strong class="cc"><?php echo $value['usename'] ?></strong><?php echo $value['liuyan'] ?> <a href="#" class="alert-link"><?php echo date('Y-m-d H:i:s',$value['fabusj']) ?></a><?php if(isset($_SESSION['usename']) && $_SESSION['usename']==$value['usename']) { ?><a class="de" href="./del.php?id=<?php echo $key;?>">删除</a><a class="de" href="./edit.php?id=<?php echo $key;?>">修改</a><?php }?>
    </div>
    <?php  }?>

</div>
<?php if($arrlen>2){ ?>
<div class="fy">
    <ul class="pagination pagination-lg">
        <li><?php  if($page<>1) {  ?><a href="index.php?p=<?php echo ($page-1);?>"  aria-label="Previous"><span aria-hidden="true">«</span></a><?php } ?></li>
        <?php for($i=1;$i<=$num;$i++){  ?>
        <li><a href="index.php?p=<?php echo $i;?>"><?php echo $i; ?></a></li>
        <?php } ?>
        <li><?php  if($page<>$num) {  ?><a href="index.php?p=<?php echo ($page+1);?>"  aria-label="Next"><span aria-hidden="true">»</span></a><?php } ?></li>
    </ul>
</div>
<?php } ?>
<div class="bs-example" data-example-id="simple-form-inline">
    <?php if(isset($_SESSION['usename'])) { ?>
    <form class="form-inline" action="add.php" method="post">
        <div class="form-group">
            <label class="sr-only" for="exampleInputEmail3">请发送信息</label>
            <input type="text" class="form-control" id="exampleInputEmail3"  name="usename" readonly="true" value="<?php echo $_SESSION['usename'] ;?>">
        </div>


        <button type="submit" class="btn btn-default" >发布</button>
        <div class="col-md-12  qq1">
            <textarea class="form-control content qq" name="liuyan" rows="10"></textarea>
        </div>
    </form>
    <?php }else{ ?>
    <form class="form-inline" action="add.php" method="post">
        <div class="form-group">
            <label class="sr-only" for="exampleInputEmail3">请发送信息</label>
            <input type="text" class="form-control" id="exampleInputEmail3"  name="usename"  value="">
        </div>


        <button type="button" class="btn btn-default" onclick="dj()">发布</button>
        <div class="col-md-12  qq1">
            <textarea class="form-control content qq" name="liuyan" rows="10" placeholder="登录后可以留言啦"></textarea>
        </div>
    </form>
    <?php } ?>
</div>
</body>
</html>